package com.firefighting.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.firefighting.dao.ContractMaintenanceProjectMapper;
import com.firefighting.dao.ContractMapper;
import com.firefighting.entity.Contract;
import com.firefighting.entity.ContractMaintenanceProject;

@Service
public class ContractService
{
	@Autowired
	private ContractMapper contractMapper;
	@Autowired
	private ContractMaintenanceProjectMapper contractMaintenanceProjectMapper;
	
	/*zhyan 添加合同*/
	public int addContract(Contract contract)
	{
		return contractMapper.insertSelective(contract);
	}
	
	/*zhyan 更新合同信息*/
	public int updateContract(Contract contract)
	{
		return contractMapper.updateByPrimaryKeySelective(contract);
	}
	
	/*zhyan 删除合同*/
	public int deleteContract(int id)
	{
		return contractMapper.deleteByPrimaryKey(id);
	}
	
	/*zhyan 查询合同信息*/
	public Contract queryContract(int id)
	{
		return contractMapper.selectByPrimaryKey(id);
	}
	
	/*zhyan 查询所有的合同信息*/
	public List<HashMap<String, Object>> queryAllContract()
	{
		return contractMapper.selectAllContract();
	}
   //liuxc 查询所属企业的所有合同
	public List<HashMap<String, Object>> getContractByEnterpriseId(Integer enterpriseId) {
		// TODO Auto-generated method stub
		return contractMapper.getContractByEnterpriseId(enterpriseId);
	}
	//Hanjd 查询所属企业的所有合同
	
	public List<Contract> getContractByEnterpriseId1(int enterpriseId) {
		// TODO Auto-generated method stub
		return contractMapper.getContractByEnterpriseId1(enterpriseId);
	}
	//Hanjd 查询主页展示所属企业的所有合同
	
	public List<HashMap<String, Object>> queryIndexContractHash(int enterpriseId) {
		// TODO Auto-generated method stub
		return contractMapper.queryIndexContractHash(enterpriseId);
	}
	//Hanjd 查询项目负责人主页展示所有合同
	
	public List<HashMap<String, Object>> queryIndexContractByLeader(String  leaderId) {
		// TODO Auto-generated method stub
		return contractMapper.queryIndexContractByLeader(leaderId);
	}
	
	public List<HashMap<String, Object>> getContractByEnterpriseIdList(List<Integer> enterIdList) {
		// TODO Auto-generated method stub
		return contractMapper.getContractByEnterpriseIdList(enterIdList);
	}
    //Liuxc 根据合同id 查询合同关联的二级维保目录
	public List<Integer> selectSecondMaintenance(Integer contractId) {
		// TODO Auto-generated method stub
		return contractMaintenanceProjectMapper.getMaintenanceListByContract(contractId);
	}
/*    //更新合同中的维保项目
	public Boolean updateMantananceInContract(Integer contractId, int[] checkedIdArray) {
		// TODO Auto-generated method stub
		Boolean flag = true;
			contractMaintenanceProjectMapper.deleteByContractId(contractId);
			for(Integer item : checkedIdArray){
				ContractMaintenanceProject cmp = new ContractMaintenanceProject();
				cmp.setContractId(contractId);
				cmp.setMaintenanceId(item);
				contractMaintenanceProjectMapper.insert(cmp);
			}
		return flag;
	}*/
	
	/** zhyan 根据合同id查询对应的业主名称、项目负责人名称和企业名称及合同信息 */
	@SuppressWarnings("rawtypes")
	public List<HashMap> queryPEPMByContractIdList(List<Integer> contractIdList)
	{
		return contractMapper.selectPEPMByContractIdList(contractIdList);
	}
	
	/** zhyan 查询所有合同的id */
	public List<Integer> queryAllContractIds()
	{
		return contractMapper.selectAllContractId();
	}
	
	/** zhyan 根据合同id查询合同信息 */
	public Contract queryContractByContractID(int id)
	{
		return contractMapper.selectByPrimaryKey(id);
	}
	
	/** zhyan 查询所有合同的详细信息 */
	@SuppressWarnings("rawtypes")
	public List<HashMap> queryContractInfo()
	{
		return contractMapper.selectAllContractInfo();
	}
	
	/** zhyan 查询某省的所有合同信息 */
	@SuppressWarnings("rawtypes")
	public List<HashMap> queryContractInfoByProvince(String province)
	{
		return contractMapper.selectAllContractInfoWithProvince(province);
	}
	
	/** zhyan 查询某省该市的所有合同信息 */
	@SuppressWarnings("rawtypes")
	public List<HashMap> queryContractInfoByProvinceAndCity(String province, String city)
	{
		return contractMapper.selectAllContractInfoWithProvinceAndCity(province, city);
	}
	
	/** zhyan 查询项目负责人负责的合同 */
	@SuppressWarnings("rawtypes")
	public List<HashMap> queryContractInfoByProjectLeaderAccount(String projectLeaderAccount)
	{
		return contractMapper.selectAllContractInfoWithProjectLeaderAccount(projectLeaderAccount);
	}
	
	/** zhyan 查询该企业下的所有项目负责人对应的合同 */
	@SuppressWarnings("rawtypes")
	public List<HashMap> queryAllContractInfoWithEnterprise(int enterpriseId/*List<String> list*/)
	{
		return contractMapper.selectAllContractInfoWithEnterprise(enterpriseId/*list*/);
	}
	
	/** zhyan 包含项目负责人名称的合同信息 */
	@SuppressWarnings("rawtypes")
	public HashMap queryContractHash(int id)
	{
		return contractMapper.queryContractHash(id);
	}
	
	/** zhyan 查询消防总队的合同id列表 */
	public List<Integer> queryContractIdListByProvince(String province)
	{
		return contractMapper.selectContractIdListByProvince(province);
	}
	
	/** zhyan 查询消防支队的合同id列表 */
	public List<Integer> queryContractIdListByProvinceAndCity(String province, String city)
	{
		return contractMapper.selectContractIdListByProvinceAndCity(province, city);
	}
	
	/** zhyan 查询项目负责人负责的所有合同的id列表 */
	public List<Integer> queryContractIdByProjectLeaderAccount(String projectLeaderAccount)
	{
		return contractMapper.selectContractIdByProjectLeaderAccount(projectLeaderAccount);
	}
	
	/** zhyan 根据企业id查询该企业所有的合同的id列表 */
	public List<Integer> queryContractIdListByEnterpriseId(int enterpriseId)
	{
		return contractMapper.selectContractIdListByEnterpriseId(enterpriseId);
	}
//根据合同ID查询合同信息
	public HashMap<String, Object> getContractInfoById(int contractId) {
		// TODO Auto-generated method stub
		return contractMapper.getContractInfoById(contractId);
	}



}